from django.contrib import admin
from .models import *


class BlogAdmin(admin.ModelAdmin):
    list_display = ('nid', 'title', 'site', 'theme',)
    list_per_page = 20
    ordering = ('-nid',)
    list_editable = ['title', 'site', 'theme']
    list_filter = ('title', 'site', 'theme',)  # 过滤器
    search_fields = ('title', 'site', 'theme')  # 搜索字段
    readonly_fields = ['nid']


class UserInfoAdmin(admin.ModelAdmin):
    list_display = ('nid', 'phone', 'avatar', 'blog', 'create_time')
    list_per_page = 20
    ordering = ('-nid',)
    list_editable = ['phone', 'avatar', 'blog']
    list_filter = ('phone', 'avatar', 'blog')  # 过滤器
    search_fields = ('phone', 'avatar', 'blog')  # 搜索字段
    readonly_fields = ['nid', 'create_time']


class CategoryAdmin(admin.ModelAdmin):
    list_display = ('nid', 'title', 'blog')
    ordering = ('-nid',)
    list_editable = ['title', 'blog']
    list_filter = ('title', 'blog')
    search_fields = ('title', 'blog')
    readonly_fields = ['nid']


class TagAdmin(admin.ModelAdmin):
    list_display = ('nid', 'title', 'blog')
    ordering = ('-nid',)
    list_editable = ['title', 'blog']
    list_filter = ('title', 'blog')
    search_fields = ('title', 'blog')
    readonly_fields = ['nid']


class ArticleAdmin(admin.ModelAdmin):
    list_display = ('nid', 'title', 'desc', 'category', 'user', 'comment_count', 'up_count', 'down_count')
    ordering = ('-nid',)
    list_editable = ('title', 'desc', 'category', 'user', 'comment_count', 'up_count', 'down_count')
    list_filter = ('title', 'desc', 'category', 'user', 'comment_count', 'up_count', 'down_count')
    search_fields = ('title', 'desc', 'category', 'user', 'comment_count', 'up_count', 'down_count')
    readonly_fields = ['nid']






class ArticleDetailAdmin(admin.ModelAdmin):
    list_display = ('nid', 'content', 'article')
    ordering = ('-nid',)
    list_editable = ['article']
    list_filter = ('content', 'article')
    search_fields = ('content', 'article')
    readonly_fields = ['nid']


class Article2TagAdmin(admin.ModelAdmin):
    list_display = ('nid', 'tag', 'article')
    ordering = ('-nid',)
    list_editable = ['article']
    list_filter = ('tag', 'article')
    search_fields = ('tag', 'article')
    readonly_fields = ['nid']


class ArticleUpDownAdmin(admin.ModelAdmin):
    list_display = ('nid', 'user', 'article', 'is_up')
    ordering = ('-nid',)
    list_editable = ['article']
    list_filter = ('article',)
    search_fields = ('tag', 'article')
    readonly_fields = ['nid']


class CommentAdmin(admin.ModelAdmin):
    list_display = ('nid', 'user', 'article', 'content', 'create_time', 'parent_comment')
    ordering = ('-nid',)
    list_editable = ['user', 'article', 'content']
    list_filter = ('user', 'article', 'content', 'parent_comment')
    search_fields = ('user', 'article', 'content', 'create_time', 'parent_comment')
    readonly_fields = ['nid', 'create_time']


class MyAdminSite(admin.AdminSite):
    site_header = '博客后台管理系统'  # 此处设置页面显示标题
    site_title = '博客后台管理'  # 此处设置页面头部标题


admin_site = MyAdminSite(name='management')

admin.site.register(UserInfo, UserInfoAdmin)
admin.site.register(Article, ArticleAdmin)
admin.site.register(Blog, BlogAdmin)
admin.site.register(Tag, TagAdmin)
admin.site.register(Category, CategoryAdmin)
admin.site.register(Comment, CommentAdmin)
admin.site.register(ArticleUpDown, ArticleUpDownAdmin)
admin.site.register(ArticleDetail, ArticleDetailAdmin)
admin.site.register(Article2Tag, Article2TagAdmin)
